package cn.limc.ohoscharts.demo.slice;

import cn.limc.ohoscharts.demo.common.BaseAbility;
import cn.limc.ohoscharts.demo.ResourceTable;
import cn.limc.ohoscharts.axis.Axis;
import cn.limc.ohoscharts.entity.DateValueEntity;
import cn.limc.ohoscharts.entity.LineEntity;
import cn.limc.ohoscharts.view.LineChart;
import ohos.aafwk.content.Intent;
import ohos.agp.utils.Color;

import java.util.ArrayList;
import java.util.List;

public class LineChartAbility extends BaseAbility {


  LineChart linechart;

  @Override
  protected void onStart(Intent intent) {
    super.onStart(intent);
    setUIContent(ResourceTable.Layout_ability_line_chart);
    initLineChart();
  }


//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//        // Inflate the menu; this adds items to the action bar if it is present.
//        getMenuInflater().inflate(R.menu.line_chart, menu);
//        return true;
//    }

  private void initLineChart() {
    this.linechart = (LineChart) findComponentById(ResourceTable.Id_linechart);
    List<LineEntity<DateValueEntity>> lines = new ArrayList<LineEntity<DateValueEntity>>();

    // 计算5日均线
    LineEntity<DateValueEntity> MA5 = new LineEntity<DateValueEntity>();
    MA5.setTitle("MA5");
    MA5.setLineColor(Color.WHITE.getValue());
    MA5.setLineData(initMA(5));
    lines.add(MA5);

    // 计算10日均线
    LineEntity<DateValueEntity> MA10 = new LineEntity<DateValueEntity>();
    MA10.setTitle("MA10");
    MA10.setLineColor(Color.RED.getValue());
    MA10.setLineData(initMA(10));
    lines.add(MA10);

    // 计算25日均线
    LineEntity<DateValueEntity> MA25 = new LineEntity<DateValueEntity>();
    MA25.setTitle("MA25");
    MA25.setLineColor(Color.GREEN.getValue());
    MA25.setLineData(initMA(25));
    lines.add(MA25);

    linechart.setAxisXColor(Color.LTGRAY.getValue());
    linechart.setAxisYColor(Color.LTGRAY.getValue());
    linechart.setBorderColor(Color.LTGRAY.getValue());
    linechart.setLongitudeFontSize(14);
    linechart.setLongitudeFontColor(Color.WHITE.getValue());
    linechart.setLatitudeColor(Color.GRAY.getValue());
    linechart.setLatitudeFontColor(Color.WHITE.getValue());
    linechart.setLongitudeColor(Color.GRAY.getValue());
    linechart.setMaxValue(280);
    linechart.setMinValue(240);
    linechart.setMaxPointNum(36);
    linechart.setDisplayLongitudeTitle(true);
    linechart.setDisplayLatitudeTitle(true);
    linechart.setDisplayLatitude(true);
    linechart.setDisplayLongitude(true);
    linechart.setLatitudeNum(5);
    linechart.setLongitudeNum(6);
    linechart.setDataQuadrantPaddingTop(5);
    linechart.setDataQuadrantPaddingBottom(5);
    linechart.setDataQuadrantPaddingLeft(5);
    linechart.setDataQuadrantPaddingRight(5);
    // linechart.setAxisYTitleQuadrantWidth(50);
    // linechart.setAxisXTitleQuadrantHeight(20);
    linechart.setAxisXPosition(Axis.AXIS_X_POSITION_BOTTOM);
    linechart.setAxisYPosition(Axis.AXIS_Y_POSITION_RIGHT);

    // 为chart1增加均线
    linechart.setLinesData(lines);
  }
}
